package com.jyhg.core.common.utils
{
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.SimpleButton;
	import flash.text.TextField;
	
	/**
	 * SimpletButtonUtil
	 * @author 韩露   hanlu.lu@snda.com
	 * $Id:$
	 * @version 1.0
	 * 设置sb的字体和文本文字
	 */
	public class SimpleButtonUtil
	{
		
		private  static var  _states:Array = ["upState", "downState", "hitTestState", "overState"];
		
		public function SimpleButtonUtil()
		{
		}
		
		public static function setText(sb:SimpleButton, text:String):void{
			for each(var state:String in _states){
				var stateDis:DisplayObject = sb[state];
				if(stateDis == null){
					continue;
				}
				setTextFiedText(stateDis, text);
			}
		}
		
		public static function setFont(sb:SimpleButton, fontName:String = "text"):void{
			for each(var state:String in _states){
				var stateDis:DisplayObject = sb[state];
				if(stateDis == null){
					continue;
				}
				setTextFiedFont(stateDis, fontName);
			}
		}
		
		public static function setTextFiedText(dis:DisplayObject, text:String):void{
			if(dis is TextField){
				TextField(dis).htmlText = text;
				TextField(dis).mouseEnabled = false;
			}
			if(dis is DisplayObjectContainer){
				var c:DisplayObjectContainer = dis as DisplayObjectContainer;
				for(var i:int; i<c.numChildren; i++){
					setTextFiedText(c.getChildAt(i), text);
				}
			}
		}
		
		private static function setTextFiedFont(dis:DisplayObject, fontName:String = "text"):void{
			if(dis is TextField){
//				FontUtils.setTextFont(TextField(dis), fontName);
			}
			if(dis is DisplayObjectContainer){
				var c:DisplayObjectContainer = dis as DisplayObjectContainer;
				for(var i:int; i<c.numChildren; i++){
					setTextFiedFont(c.getChildAt(i), fontName);
				}
			}
		}
	}
}
